<?php
$path = dirname(__FILE__);

// error reporting
error_reporting(E_ALL ^ ~E_NOTICE ^ ~E_WARNING);

// Add app/ and vendor/ to PHP's include path
$include_path[] = ini_get("include_path");
$include_path[] = "app/";
$include_path[] = "app/views/";
$include_path[] = "vendor/";
ini_set("include_path", implode(strpos($_SERVER['SERVER_SOFTWARE'], 'Win')? ';': ':',$include_path));

// we want session
session_start();

// we need it for configuration
require_once $path . '/vendor/pimp/Singleton.php';
use PIMP::Base::e;
use PIMP::Base::Singleton;

// Include configuration
if (file_exists($path . '/local/Configuration.php'))
	require_once $path . '/local/Configuration.php';
else
	require_once $path . '/Configuration.php';

// Include all pimp classes
$handle = opendir($path . '/vendor/pimp/');
while (false !== ($file = readdir ($handle))) {
	if ($file != "." && $file != ".." && strpos($file, ".php") != false && strpos($file, "#") === false && strpos($file, ".swp") === false  ) { 
		include_once $path . '/vendor/pimp/' . $file; 
    }
}
closedir($handle);

// Load model classes on the fly
function model_autoload($class_name) {
    $path = dirname(__FILE__);
	$class_name = $class_name;
	require_once $path . "/app/models/{$class_name}.php";
}
spl_autoload_register('model_autoload'); 

// Initialise Database connection
Database::establish_connection();
?>
